<template>
	<view class="nft_container_bg">
		<view class="buyNft">
			<!-- 封面 -->
			<view class="nft_cover">
				<image :src="nftDetailsInfo.metadataImage" mode=""></image>
			</view>
			<!-- 信息展示 -->
			<view class="nft_order_card">
				<view class="nft_order_conent">
					<view class="nft_order_conent_title">
						{{nftDetailsInfo.goodsName}}
					</view>
					<view class="nft_order_conent_series">
						<view class="">系列</view>
						<view class="">无系列</view>
					</view>
					<view class="nft_order_conent_series">
						<view class="">单价</view>
						<view class="">{{nftDetailsInfo.price}}</view>
					</view>
					<view class="nft_order_conent_series info_approve_content">
						<view class="">合约地址</view>
						<view class="info_approve_contract">
							<span class="info">
								{{nftDetailsInfo.contract.contract}}
							</span>
							<span class="icon" @click="copyContract">
								<image style="width: 20px;height: 20px;" src="../../static/img/nft/copy.png"></image>
							</span>
						</view>

					</view>
					<view class="nft_order_conent_series">
						<view class="">认证标识</view>
						<view class="">{{nftDetailsInfo.contractTemplate.type}}</view>
					</view>
				</view>
			</view>
			<!-- 购买数量 -->
			<view class="nft_order_card">
				<view class="nft_order_conent">
					<view class="nft_order_num">
						<view class="">购买数量</view>
						<u-number-box v-model="buyNum" @change="changeBuyNum"></u-number-box>
					</view>
					<view class="nft_order_">
						<view class="">{{buyNum}}件商品，商品总金额</view>
						<view class="">¥{{ totalAmount }}</view>
					</view>
				</view>
			</view>
			<!-- 底部按钮 -->
			<view class="bottom_btn_card">
				<view class="bottom_btn_card_left">
					<view class="price">¥{{ totalAmount }}</view>
				</view>
				<view class="">
					<u-button text="立即购买" color="var(--echo-main-color)" @tap="topay" class="bottom_btn"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getGoodsDetails
	} from '@/config/nftApi.js';
	export default {
		data() {
			return {
				buyNum: 1,
				// 产品信息
				nftDetailsInfo: {},
				// 总金额
				totalAmount: 0,
				// 商品编号
				serialNo: ''
			}
		},
		onLoad({
			serialNo
		}) {
			this.serialNo = serialNo
			getGoodsDetails({
				serialNo
			}).then(res => {
				if (res) {
					this.nftDetailsInfo = res.data
					console.log('this.nftDetailsInfo', this.nftDetailsInfo)
					this.totalAmount = res.data.price
				}
			})
		},
		methods: {
			copyContract() {
				uni.setClipboardData({
					data: this.nftDetailsInfo.contract.contract,
					success: function () {
						console.log('success');
					},
				});
			},
			changeBuyNum(e) {
				console.log(e.value)
				// console.log('this.buyNum', this.buyNum)
				this.totalAmount = e.value * this.nftDetailsInfo.price
			},
			topay() {
				uni.navigateTo({
					url: "/pages/nft/payNft?totalAmount=" + this.totalAmount + '&serialNo=' + this.serialNo
				})
			}
		}
	}
</script>
<style lang="scss">
	.nft_container_bg {
		min-height: 100vh;
		background: $echo-nft-bg-color;
		.buyNft {
			padding: 0 20rpx;
			color: #fff;
			.nft_cover {
				width: 100%;
				height: 400rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.nft_order_card {
				font-size: 28rpx;
				margin-bottom: 30rpx;
				.nft_order_conent {
					background-color: $echo-nft-card-bg-color;
					padding: 30rpx;
					border-radius: 10rpx;
					&>view {
						margin-bottom: 30rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
					}
					&>view:last-child {
						margin-bottom: 0;
					}
				}

				.info_approve_content {
					overflow: hidden;
					margin-bottom: 30rpx;
					.info_approve_contract {
						span {
							display: inline-block;
						}
						.info {
							width: 400rpx;
							/*1.强制不换行*/
							white-space: nowrap;
							/*2.溢出隐藏*/
							overflow: hidden;
							/*3.超出部分用省略号表示*/
							text-overflow: ellipsis;
						}
					}
					&>view {
						display: flex;
						justify-content: space-between;
						font-size: 28rpx;
					}

					&>view:first-child {
						margin-bottom: 30rpx;
					}
				}

			}

			// 底部按钮
			.bottom_btn_card {
				width: 100%;
				box-sizing: border-box;
				position: fixed;
				bottom: 0;
				left: 0;
				padding: 0 60rpx;
				height: 110rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: $echo-nft-card-bg-color;
				font-size: 28rpx;

				&_left {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.price {
						font-size: 44rpx;
						color: $echo-main-color;
						margin-left: 20rpx;
					}
				}

				.bottom_btn {
					border-radius: 40rpx;
					width: 200rpx;
				}
			}
		}
	}
</style>
